/*global nw:true, window */

"use strict";

window.nw = window.nw || {};
nw.module = nw.module || {};

nw.module.M1 = function(sandbox) {
    nw.module.base.call(this, sandbox);
    //this._sandbox = sandbox;
    this._mapping = {
        container: "#m1-view-container",
        template: "#m1-view-template",
        goView2: ".js-goView2",
        goView3: ".js-goView3"
    };
    //this._rendered = false;
};

function inheritPrototype(subType, superType){
    var prototype = Object(superType.prototype); //create object
    prototype.constructor = subType; //augment object
    subType.prototype = prototype; //assign object
}

inheritPrototype(nw.module.M1, nw.module.base);

//nw.module.M1.prototype = {
////	init: function(config) {
////		this._config = config;
////    },
//    render: function() {
//        if(this._rendered) {
//            return this;
//        }
//
//        if(this._sandbox.getCurrentViewName() === this._sandbox.views().v1) {
//            this._sandbox.render(this._mapping.template, this._mapping.container, {header: 'module #1'});
//
//            this._sandbox.onClick(this._mapping.goView2, this._goView2.bind(this));
//            this._sandbox.onClick(this._mapping.goView3, this._goView3.bind(this));
//
//            this._rendered = true;
//        }
//
//        return this;
//    },
////    show: function() {
////        this.render();
////        this._sandbox.show(this._mapping.container);
////    },
////    hide: function() {
////        this._sandbox.hide(this._mapping.container); //.style.display = 'none';
////    },
//	_goView2: function() {
//        this._sandbox.goView(nw.enums.views.v2);
//	},
//	_goView3: function() {
//        this._sandbox.goView(nw.enums.views.v3);
//	}
//};

nw.module.M1.prototype.render = function() {
        if(this._rendered) {
            return this;
        }

        if(this._sandbox.getCurrentViewName() === this._sandbox.views().v1) {
            this._sandbox.render(this._mapping.template, this._mapping.container, {header: 'module #1'});

            this._sandbox.onClick(this._mapping.goView2, this._goView2.bind(this));
            this._sandbox.onClick(this._mapping.goView3, this._goView3.bind(this));

            this._rendered = true;
        }

        return this;
    };
nw.module.M1.prototype._goView2 = function() {
        this._sandbox.goView(nw.enums.views.v2);
    };
nw.module.M1.prototype._goView3 = function() {
        this._sandbox.goView(nw.enums.views.v3);
    };